package com.jiangxiaofei.citycloud.util;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.net.Uri;

import com.jiangxiaofei.citycloud.view.IOSAlertDialog;

/**
 * @author: JiangXFei
 * @date: 2017/11/29 0029
 * @content:权限管理工具
 */

public class PermissionUtil {

    private PermissionUtil() {
    }

    private static Context mContext;
    private static Activity mActivity;
    /**
     * 获取位置权限
     */
    private String[] permsLoaction = {Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION};

    /**
     * 获取拨打电话权限
     */
    private String permsCallPhone = Manifest.permission.CALL_PHONE;
    /**
     * 获取手机信息权限
     */
    private String permsPhoneState = Manifest.permission.READ_PHONE_STATE;

    private String[] permsStorage = {
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE};
    private Location newLocation;

    public static PermissionUtil init(Activity activity) {
        mContext = activity;
        mActivity = activity;
        return new PermissionUtil();
    }

    /**
     * 拨打电话
     */
    @SuppressLint("MissingPermission")
    public static void CallPhone(Context mContext, String phoneNum) {
        IOSAlertDialog dialog = new IOSAlertDialog(mContext);
        dialog.builder()
                .setTitle("联系卖家")
                .setMsg("是否拨打：" + phoneNum)
                .setCancelable(true)
                .setNegativeButton("取消", v2 -> {

                }).setPositiveButton("确定", v1 -> {
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNum));
            mContext.startActivity(intent);
        }).show();
    }

    public static void sendMsg(Context mContext, String phoneNum) {
        IOSAlertDialog dialog = new IOSAlertDialog(mContext);
        dialog.builder()
                .setTitle("联系卖家")
                .setMsg("即将进入短信编辑页面发送短信")
                .setCancelable(true)
                .setNegativeButton("取消", v2 -> {

                }).setPositiveButton("确定", v1 -> {
            Uri smsToUri = Uri.parse("smsto:"+phoneNum);
            Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri);
            intent.putExtra("sms_body", "");
            mContext.startActivity(intent);
        }).show();

    }

}
